<html>
<head><meta charset="utf-8"><title>what does short-circuiting mean for evaluation/drop order? · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20does.20short-circuiting.20mean.20for.20evaluation.2Fdrop.20order.3F.html">what does short-circuiting mean for evaluation/drop order?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="217043442"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20does%20short-circuiting%20mean%20for%20evaluation/drop%20order%3F/near/217043442" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20does.20short-circuiting.20mean.20for.20evaluation.2Fdrop.20order.3F.html#217043442">(Nov 17 2020 at 18:32)</a>:</h4>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">use</span><span class="w"> </span><span class="n">std</span>::<span class="n">cell</span>::<span class="n">RefCell</span><span class="p">;</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">RefCell</span>::<span class="n">new</span><span class="p">(</span><span class="kc">true</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="o">*</span><span class="n">x</span><span class="p">.</span><span class="n">borrow_mut</span><span class="p">()</span><span class="w"> </span><span class="o">&amp;&amp;</span><span class="w"> </span><span class="o">*</span><span class="n">x</span><span class="p">.</span><span class="n">borrow_mut</span><span class="p">();</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<div class="codehilite"><pre><span></span><code>thread &#39;main&#39; panicked at &#39;already borrowed: BorrowMutError&#39;, src/main.rs:8:27
</code></pre></div>
<p>Presumably the <code>drop</code> of the LHS isn't happening until the whole statement is complete?</p>



<a name="217043516"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20does%20short-circuiting%20mean%20for%20evaluation/drop%20order%3F/near/217043516" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20does.20short-circuiting.20mean.20for.20evaluation.2Fdrop.20order.3F.html#217043516">(Nov 17 2020 at 18:32)</a>:</h4>
<p>Yeah, temporary values live for the entire duration of the statement they are created in.</p>



<a name="217043659"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20does%20short-circuiting%20mean%20for%20evaluation/drop%20order%3F/near/217043659" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20does.20short-circuiting.20mean.20for.20evaluation.2Fdrop.20order.3F.html#217043659">(Nov 17 2020 at 18:33)</a>:</h4>
<p>Related: <a href="https://github.com/rust-lang/rust/pull/75671#issuecomment-684902197">https://github.com/rust-lang/rust/pull/75671#issuecomment-684902197</a></p>



<a name="217044675"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20does%20short-circuiting%20mean%20for%20evaluation/drop%20order%3F/near/217044675" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20does.20short-circuiting.20mean.20for.20evaluation.2Fdrop.20order.3F.html#217044675">(Nov 17 2020 at 18:41)</a>:</h4>
<blockquote>
<p>Apart from lifetime extension, the temporary scope of an expression is the smallest scope that contains the expression and is for one of the following:<br>
...<br>
   The second operand of a lazy boolean expression.<br>
- <a href="https://doc.rust-lang.org/reference/destructors.html#temporary-scopes">reference</a></p>
</blockquote>
<p>I wonder why <em>second</em> is special but not first.</p>



<a name="217045210"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20does%20short-circuiting%20mean%20for%20evaluation/drop%20order%3F/near/217045210" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20does.20short-circuiting.20mean.20for.20evaluation.2Fdrop.20order.3F.html#217045210">(Nov 17 2020 at 18:44)</a>:</h4>
<p>So this case is expanded to </p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">t1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">x</span><span class="p">.</span><span class="n">borrow_mut</span><span class="p">();</span><span class="w"></span>

<span class="w">    </span><span class="o">*</span><span class="n">t1</span><span class="w"> </span><span class="o">&amp;&amp;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">t2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">x</span><span class="p">.</span><span class="n">borrow_mut</span><span class="p">();</span><span class="w"></span>
<span class="w">        </span><span class="o">*</span><span class="n">t2</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="217045257"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20does%20short-circuiting%20mean%20for%20evaluation/drop%20order%3F/near/217045257" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20does.20short-circuiting.20mean.20for.20evaluation.2Fdrop.20order.3F.html#217045257">(Nov 17 2020 at 18:45)</a>:</h4>
<p>but why was that chosen instead of</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">t1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">x</span><span class="p">.</span><span class="n">borrow_mut</span><span class="p">();</span><span class="w"></span>
<span class="w">        </span><span class="o">*</span><span class="n">t1</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"> </span><span class="o">&amp;&amp;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">t2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">x</span><span class="p">.</span><span class="n">borrow_mut</span><span class="p">();</span><span class="w"></span>
<span class="w">        </span><span class="o">*</span><span class="n">t2</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="217045377"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20does%20short-circuiting%20mean%20for%20evaluation/drop%20order%3F/near/217045377" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20does.20short-circuiting.20mean.20for.20evaluation.2Fdrop.20order.3F.html#217045377">(Nov 17 2020 at 18:46)</a>:</h4>
<p>Yeah I wish drop rules were simpler</p>



<a name="217045412"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20does%20short-circuiting%20mean%20for%20evaluation/drop%20order%3F/near/217045412" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20does.20short-circuiting.20mean.20for.20evaluation.2Fdrop.20order.3F.html#217045412">(Nov 17 2020 at 18:46)</a>:</h4>
<p>In particular I think <code>&amp;&lt;literal value&gt;</code> is too clever by half</p>



<a name="217045699"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20does%20short-circuiting%20mean%20for%20evaluation/drop%20order%3F/near/217045699" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> isHavvy <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20does.20short-circuiting.20mean.20for.20evaluation.2Fdrop.20order.3F.html#217045699">(Nov 17 2020 at 18:49)</a>:</h4>
<p>I often wonder at some of the drop rules as well. Some of the choices definitely feel like warts in the language to me.</p>



<a name="217046974"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20does%20short-circuiting%20mean%20for%20evaluation/drop%20order%3F/near/217046974" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20does.20short-circuiting.20mean.20for.20evaluation.2Fdrop.20order.3F.html#217046974">(Nov 17 2020 at 19:00)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116155">Jake Goulding</span> <a href="#narrow/stream/122651-general/topic/what.20does.20short-circuiting.20mean.20for.20evaluation.2Fdrop.20order.3F/near/217044675">said</a>:</p>
<blockquote>
<p>I wonder why <em>second</em> is special but not first.</p>
</blockquote>
<p>I would guess because the first always runs, but the second might not.  So any temporary from the first one makes sense to have available after the expression in a way that the second doesn't.</p>
<p>But I agree that temporary lifetimes are a bit evil.  Especially with the <code>let A = B; C</code> vs <code>match B { A =&gt; C }</code> difference...</p>



<a name="217088428"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20does%20short-circuiting%20mean%20for%20evaluation/drop%20order%3F/near/217088428" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20does.20short-circuiting.20mean.20for.20evaluation.2Fdrop.20order.3F.html#217088428">(Nov 18 2020 at 02:12)</a>:</h4>
<p>I always have to use <code>drop(g)</code> around my mutex guards because I don't trust the drop rules</p>



<a name="217088446"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20does%20short-circuiting%20mean%20for%20evaluation/drop%20order%3F/near/217088446" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20does.20short-circuiting.20mean.20for.20evaluation.2Fdrop.20order.3F.html#217088446">(Nov 18 2020 at 02:13)</a>:</h4>
<p>especially with NLL I really have no idea when drop glue runs</p>



<a name="217088555"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20does%20short-circuiting%20mean%20for%20evaluation/drop%20order%3F/near/217088555" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20does.20short-circuiting.20mean.20for.20evaluation.2Fdrop.20order.3F.html#217088555">(Nov 18 2020 at 02:15)</a>:</h4>
<p>NLL does not affect drop glue.</p>



<a name="217088727"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20does%20short-circuiting%20mean%20for%20evaluation/drop%20order%3F/near/217088727" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20does.20short-circuiting.20mean.20for.20evaluation.2Fdrop.20order.3F.html#217088727">(Nov 18 2020 at 02:18)</a>:</h4>
<p>Doesn't it have to? Because if you only ran drop glue at scope end a la classic borrow checking, because NLL allows some programs that are not well scoped in that way, you could end up accessing a value that has already been invalidated</p>



<a name="217088797"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20does%20short-circuiting%20mean%20for%20evaluation/drop%20order%3F/near/217088797" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20does.20short-circuiting.20mean.20for.20evaluation.2Fdrop.20order.3F.html#217088797">(Nov 18 2020 at 02:20)</a>:</h4>
<p>Drop glue counts as a use of a borrow, and drops always happen at the end of scope</p>



<a name="217088960"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20does%20short-circuiting%20mean%20for%20evaluation/drop%20order%3F/near/217088960" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20does.20short-circuiting.20mean.20for.20evaluation.2Fdrop.20order.3F.html#217088960">(Nov 18 2020 at 02:23)</a>:</h4>
<p>NLL doesn't change the runtime behavior of a program, it just expands the set of legal programs that compile</p>



<a name="217089029"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20does%20short-circuiting%20mean%20for%20evaluation/drop%20order%3F/near/217089029" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20does.20short-circuiting.20mean.20for.20evaluation.2Fdrop.20order.3F.html#217089029">(Nov 18 2020 at 02:24)</a>:</h4>
<p>Oh, I didn't realize that there was a difference between these situations:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">struct</span> <span class="nc">Guard</span><span class="o">&lt;'</span><span class="na">a</span><span class="o">&gt;</span><span class="p">(</span><span class="o">&amp;'</span><span class="nb">static</span><span class="w"> </span><span class="kt">str</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;'</span><span class="na">a</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="kt">u8</span><span class="p">);</span><span class="w"></span>

<span class="k">impl</span><span class="o">&lt;'</span><span class="na">a</span><span class="o">&gt;</span><span class="w"> </span><span class="nb">Drop</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">Guard</span><span class="o">&lt;'</span><span class="na">a</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">drop</span><span class="p">(</span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="bp">self</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">println</span><span class="o">!</span><span class="p">(</span><span class="s">"running drop glue for {}"</span><span class="p">,</span><span class="w"> </span><span class="bp">self</span><span class="p">.</span><span class="mi">0</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span><span class="w"></span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="n">x</span><span class="p">;</span><span class="w"></span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">z</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="n">x</span><span class="p">;</span><span class="w"> </span><span class="c1">// OK</span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span><span class="w"></span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Guard</span><span class="p">(</span><span class="s">"y"</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="n">x</span><span class="p">);</span><span class="w"></span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">z</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Guard</span><span class="p">(</span><span class="s">"z"</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="n">x</span><span class="p">);</span><span class="w"> </span><span class="c1">// error double mut</span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="217091922"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20does%20short-circuiting%20mean%20for%20evaluation/drop%20order%3F/near/217091922" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20does.20short-circuiting.20mean.20for.20evaluation.2Fdrop.20order.3F.html#217091922">(Nov 18 2020 at 03:14)</a>:</h4>
<p><a href="https://stackoverflow.com/q/57467555/155423">Will the non-lexical lifetime borrow checker release locks prematurely?</a></p>



<a name="217123802"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20does%20short-circuiting%20mean%20for%20evaluation/drop%20order%3F/near/217123802" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20does.20short-circuiting.20mean.20for.20evaluation.2Fdrop.20order.3F.html#217123802">(Nov 18 2020 at 11:41)</a>:</h4>
<p><span class="user-mention silent" data-user-id="125270">scottmcm</span> <a href="#narrow/stream/122651-general/topic/what.20does.20short-circuiting.20mean.20for.20evaluation.2Fdrop.20order.3F/near/217046974">said</a>:</p>
<blockquote>
<p>But I agree that temporary lifetimes are a bit evil.  Especially with the <code>let A = B; C</code> vs <code>match B { A =&gt; C }</code> difference...</p>
</blockquote>
<p>Tbf, that's maybe the only one that is predicatable and thus kind of makes sense (I just sometime wish we had <code>let in</code> sugar for some of these things (I also wish std locks also offered callback-based APIs, since they are less error-prone and their inability to allow inner <code>.await</code>s would actually have been a feature <em>w.r.t.</em> <code>async</code> and deadlocks)).</p>
<p>The horrendous one is <code>if let</code> and <code>while let</code> not behaving the same <span aria-label="sob" class="emoji emoji-1f62d" role="img" title="sob">:sob:</span></p>



<a name="217125577"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20does%20short-circuiting%20mean%20for%20evaluation/drop%20order%3F/near/217125577" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20does.20short-circuiting.20mean.20for.20evaluation.2Fdrop.20order.3F.html#217125577">(Nov 18 2020 at 12:03)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232018">Daniel Henry-Mantilla</span> <a href="#narrow/stream/122651-general/topic/what.20does.20short-circuiting.20mean.20for.20evaluation.2Fdrop.20order.3F/near/217123802">said</a>:</p>
<blockquote>
<p>The horrendous one is <code>if let</code> and <code>while let</code> not behaving the same <span aria-label="sob" class="emoji emoji-1f62d" role="img" title="sob">:sob:</span></p>
</blockquote>
<p>Oh? Do you have an example?</p>



<a name="217134310"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20does%20short-circuiting%20mean%20for%20evaluation/drop%20order%3F/near/217134310" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20does.20short-circuiting.20mean.20for.20evaluation.2Fdrop.20order.3F.html#217134310">(Nov 18 2020 at 13:32)</a>:</h4>
<p>My bad, I misremembered: it wasn't <code>if let</code> <em>vs.</em> <code>while let</code>, but <code>if let</code> <em>vs.</em> <code>if</code>: <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=9a2da82f9170a2d0520e14569060c56d">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=9a2da82f9170a2d0520e14569060c56d</a> (so I withdraw my <em>horrendous</em> qualification, then, since pattern-matching and expression evaluation do involve different mechanisms: I downgrade it to "a footgunny thing that may catch some people unaware")</p>



<a name="217136421"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20does%20short-circuiting%20mean%20for%20evaluation/drop%20order%3F/near/217136421" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20does.20short-circuiting.20mean.20for.20evaluation.2Fdrop.20order.3F.html#217136421">(Nov 18 2020 at 13:51)</a>:</h4>
<p>Here is a completely degenerate example: <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=1363000c4ead264020de7b9ded7f90ae">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=1363000c4ead264020de7b9ded7f90ae</a>,<br>
which is quite unrealistic, but I do expect people getting bitten by this when dealing with lock guards.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>